<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in list"  :label="item.id" :key="item.id">{{item.name}}</el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button @click="hSave" type="primary">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import {getRoles} from '@/api/settings';
import {getUserDetailById} from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props:{
     curId: {
      		type: String,
      		required: true
    		}
  }
  ,
  data() {
    return {
      roleIds: [],
      list:[]
    };
  },
  methods: {
    closeDialog() {
      this.$emit('close')
    },
    async loadRoles() {
      const res = await getRoles({ page: 1, pagesize: 100 });
      // console.log(res);
      this.list = res.data.rows;
      const info = await getUserDetailById(this.curId)
      this.roleIds = info.data.roleIds
    },
     async hSave(){
      await assignRoles({ id: this.curId, roleIds: this.roleIds })
      this.$emit('success');
    }
   
  },
   created() {
      this.loadRoles();
    },
};
</script>